package com.zp.crm.Controller.LostController;

import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.google.gson.Gson;
import com.zp.crm.service.LostService.LostService;

@Controller
@RequestMapping("/lost")
public class LostController {

		@Resource
		public LostService lostService;
		
		@RequestMapping(value="/select",method=RequestMethod.POST)
		public void SelectStuts(HttpServletRequest request,HttpServletResponse response){
			response.setContentType("text/html;charset=utf-8");
			String stuts=request.getParameter("stuts");
			String username=request.getParameter("username");
			String name=request.getParameter("name");
			String pageStr=request.getParameter("page");
			int page=1,size=10;
			if(pageStr != null){
				page=Integer.parseInt(pageStr);
			}
			Map<String, Object> map=lostService.select(stuts,username,name,page,size);
			try{
				PrintWriter out=response.getWriter();
				out.println(map.get("message"));			
			}catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		@RequestMapping(value="/selectcode",method=RequestMethod.POST)
		public void SelectCode(HttpServletRequest request,HttpServletResponse response){
			response.setContentType("text/html;charset=utf-8");
			String code=request.getParameter("code");
			Map<String, Object> map=lostService.selectCode(code);
			try{
				PrintWriter out=response.getWriter();
				String json=new Gson().toJson(map);
				out.println(json);			
			}catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		
		@RequestMapping(value="/edit",method=RequestMethod.POST)
		public void Edit(HttpServletRequest request,HttpServletResponse response){
			response.setContentType("text/html;charset=utf-8");
			String code=request.getParameter("code");
			String zhcs=request.getParameter("zhcs");
			String lsyy=request.getParameter("lsyy");
			String stuts=request.getParameter("stuts");
			Map<String, Object> map=lostService.edit(code,zhcs,lsyy,stuts);
			try{
				PrintWriter out=response.getWriter();
				String json=new Gson().toJson(map);
				out.println(json);			
			}catch (Exception e) {
				e.printStackTrace();
			}

			
		}
		
}
